package com.example.icampusevent;

import java.util.ArrayList;

import android.os.Bundle;
import android.app.ListFragment;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.Toast;

public class EventCategoryFragment extends ListFragment {
	
	private String[] categories = {"ALL", "MUSIC", "SPORTS", "FILM", "WORKSHOP", "ACDAMIC", 
    		"EXHIBIT", "OTHER"};
	
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setListAdapter(new EventCategoryAdapter(getActivity()));
    }

    public ArrayList<String> getCheckedCategory() {
    	ArrayList<String> selected = new ArrayList<String>();
    	
    	EventCategoryAdapter adapter = (EventCategoryAdapter) getListAdapter();
    	CheckBox checkBox = (CheckBox)adapter.getItem(0);
    	if(checkBox.isChecked()) {
    		selected.add("ALL");
    		return selected;
    	}
    	for(int i = 1; i < 8; i++) {
    		checkBox = (CheckBox)adapter.getItem(i);
        	if(checkBox.isChecked()) {
        		selected.add(categories[i]);
        	}
    	}
    	
    	if(selected.isEmpty()) {
    		selected.add("ALL");
    	}
    	return selected;
    }
    
    public void toast(String s) {
		CharSequence text = s;
		int duration = Toast.LENGTH_LONG;
		Toast toast = Toast.makeText(getActivity(), text, duration);
		toast.show();
	}
}
